//
//  OldPhotoUploadCollectionCell.m
#import "OldPhotoUploadCollectionCell.h"
@interface OldPhotoUploadCollectionCell()
@property (nonatomic, strong) UIImageView *oldPhotoUploadImgView;
@property (nonatomic,strong) UILabel *oldPhotoUploadBottomLab;
@property (nonatomic, strong) UIImageView *oldPhotoUploadPhotoImgView;
@end
@implementation OldPhotoUploadCollectionCell
-(instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self creatOldPhotoSubView];
    }
    return self;
}
- (void)creatOldPhotoSubView{
    self.oldPhotoUploadImgView = [[UIImageView alloc] init];
    self.oldPhotoUploadImgView.layer.cornerRadius = OldPhotoRatio(20);
    self.oldPhotoUploadImgView.clipsToBounds = true;
    self.oldPhotoUploadImgView.userInteractionEnabled = YES;
    [self addSubview:self.oldPhotoUploadImgView];
    [self.oldPhotoUploadImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(OldPhotoRatio(0)));
    }];
    self.oldPhotoUploadBottomLab = [[UILabel alloc] init];
    self.oldPhotoUploadBottomLab.textColor = OldPhotoHex(@"#FFFFFF");
    self.oldPhotoUploadBottomLab.font = [UIFont systemFontOfSize:OldPhotoRatio(30) weight:UIFontWeightRegular];
    self.oldPhotoUploadBottomLab.hidden = true;
    self.oldPhotoUploadBottomLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.oldPhotoUploadBottomLab];
    [self.oldPhotoUploadBottomLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(OldPhotoRatio(0)));
        make.right.equalTo(@(OldPhotoRatio(0)));
        make.height.equalTo(@(OldPhotoRatio(112)));
        make.bottom.equalTo(@(OldPhotoRatio(0)));
    }];
    self.oldPhotoUploadPhotoImgView = [[UIImageView alloc] init];
    self.oldPhotoUploadPhotoImgView.layer.cornerRadius = OldPhotoRatio(20);
    self.oldPhotoUploadPhotoImgView.clipsToBounds = true;
    self.oldPhotoUploadPhotoImgView.userInteractionEnabled = YES;
    self.oldPhotoUploadPhotoImgView.hidden = true;
    [self addSubview:self.oldPhotoUploadPhotoImgView];
    [self.oldPhotoUploadPhotoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(OldPhotoRatio(0)));
    }];
}
-(void)setOldPhotoUploadDic:(NSDictionary *)oldPhotoUploadDic{
    _oldPhotoUploadDic = oldPhotoUploadDic;
    NSString * index = [_oldPhotoUploadDic objectForKey:@"index"];
    NSString * name =  [_oldPhotoUploadDic objectForKey:@"name"];
    NSString * img =  [_oldPhotoUploadDic objectForKey:@"img"];
    if (index.length > 0) {
        self.oldPhotoUploadBottomLab.hidden = true;
        NSString *oldPhotoImg = [NSString stringWithFormat:@"OldPhotoUpload%@",index];
        self.oldPhotoUploadImgView.image = OldPhotoImageNamed(oldPhotoImg);
    }else{
        self.oldPhotoUploadBottomLab.hidden = false;
        self.oldPhotoUploadImgView.image = OldPhotoImageNamed(@"OldPhotoUploadDef");
        self.oldPhotoUploadBottomLab.text = name;
    }
    if (img.length > 0) {
        self.oldPhotoUploadPhotoImgView.hidden = false;
        NSData * olPhotoData = [[NSData alloc] initWithBase64EncodedString:img options:NSDataBase64Encoding64CharacterLineLength];;
        self.oldPhotoUploadPhotoImgView.image = [UIImage imageWithData:olPhotoData];
    }else{
        self.oldPhotoUploadPhotoImgView.hidden = true;
    }
}
@end
